Create a delegate for MapboxNavigation called requireMapboxNavigation#6233
Merged
Create a delegate for MapboxNavigation called requireMapboxNavigation#6233
MapboxNavigation called requireMapboxNavigation#6233Conversation
Codecov Report
@@ Coverage Diff @@
## main #6233 +/- ##
============================================
+ Coverage 68.81% 68.84% +0.02%
- Complexity 4346 4348 +2
============================================
Files 649 650 +1
Lines 26183 26223 +40
Branches 3067 3075 +8
============================================
+ Hits 18019 18052 +33
- Misses 6998 7001 +3
- Partials 1166 1170 +4
|
7d11345 to
0f6a748
Compare
kmadsen
commented
Aug 25, 2022
|
|
||
| override fun onStop() { | ||
| super.onStop() | ||
| mapboxNavigation.unregisterRouteProgressObserver(replayProgressObserver) |
Contributor
Author
There was a problem hiding this comment.
This is a bug. If you background the app it will unsubscribe. The subscribe happens in onCreate so the subscription is lost.
e92feb7 to
e8c6b00
Compare
dzinad
reviewed
Aug 26, 2022
...n-core/src/main/java/com/mapbox/navigation/core/lifecycle/RequireMapboxNavigationDelegate.kt
Show resolved
Hide resolved
...re/src/test/java/com/mapbox/navigation/core/lifecycle/RequireMapboxNavigationDelegateTest.kt
Show resolved
Hide resolved
Zayankovsky
reviewed
Aug 26, 2022
qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/FeedbackActivity.kt
Outdated
Show resolved
Hide resolved
20250d4 to
254b936
Compare
kmadsen
commented
Aug 30, 2022
libnavigation-core/src/main/java/com/mapbox/navigation/core/lifecycle/MapboxNavigationOwner.kt
Show resolved
Hide resolved
027af78 to
1d63ae9
Compare
kmadsen
commented
Sep 1, 2022
...n-core/src/main/java/com/mapbox/navigation/core/lifecycle/RequireMapboxNavigationDelegate.kt
Show resolved
Hide resolved
64e6ff6 to
13785bf
Compare
kmadsen
commented
Sep 2, 2022
| mapboxNavigation.unregisterLocationObserver(locationObserver) | ||
| mapboxNavigation.stopTripSession() | ||
| } | ||
| private val mapboxNavigation by requireMapboxNavigation( |
Contributor
Author
There was a problem hiding this comment.
This never loads unless you reference it. The lazy load can be confusing.
Also, the onCreate callback from activity happens before the Lifecycle onCreate. That causes a crash if you try to reference this delegate without using Lifecycle callbacks.
Contributor
Author
There was a problem hiding this comment.
Fixed it but was finding another race condition along the way.
mapboxNavigation.setRoutes(listOf(route))
binding.startNavigation.visibility = View.GONE
startSimulation(mapboxNavigation.getRoutes()[0]) <=== crashes because routes are not set yet
Zayankovsky
approved these changes
Sep 5, 2022
Zayankovsky
reviewed
Sep 5, 2022
...avigation-core/src/main/java/com/mapbox/navigation/core/lifecycle/RequireMapboxNavigation.kt
Outdated
Show resolved
Hide resolved
8a8286f to
aa87a7d
Compare
kmadsen
commented
Sep 6, 2022
...avigation-core/src/main/java/com/mapbox/navigation/core/lifecycle/RequireMapboxNavigation.kt
Show resolved
Hide resolved
aa87a7d to
6234305
Compare
6234305 to
b145c53
Compare
0b3b832 to
8dbc73a
Compare
Zayankovsky
approved these changes
Sep 6, 2022
Guardiola31337
pushed a commit
that referenced
this pull request
Dec 22, 2022
…ion` (#6233) * Create a delegate for MapboxNavigation * Make requireMapboxNavigation attach during initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
There is some consistent boilerplate required to setup the
MapboxNavigationApp. I've just spent a bit of time migrating:libnavui-androidauto:to use theMapboxNavigationApp#6141 and I've explored a few approaches with the examples repository mapbox/mapbox-navigation-android-examples#129. We also discussed some ambiguous scenarios where we want to accessMapboxNavigationdirectly and it requires an unsafe callMapboxNavigationApp.current()!!. #6226 (comment). This delegate removes the need for!!with specific guidelines.This is my favorite approach so far. Create a delegate that hooks up
MapboxNavigationto yourLifecycleOwner. I migrated a random example from theqa-test-appto show what it looks like, take a look at theFeedbackActivity. EDIT migrated another exampleInactiveRouteStylingActivity.Screenshots or Gifs
Inside any
LifecycleOwneryou can use therequireMapboxNavigationdelegate like this. And then you have access tomapboxNavigationas if you constructed it inside.Default can be used when [MapboxNavigationApp] is setup elsewhere.
val mapboxNavigation by requireMapboxNavigation()Initialize the [MapboxNavigationApp] when you are ready to use it
Initialize and setup subscriptions
Another example